#pragma once

#include <pthread.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>

#include <linux/input.h>
#include <linux/joystick.h>

#define NAME_LENGTH 128

void *threadFunc(void *input);

class Joystick
{

public:
    // Constructors
    Joystick(const char* device);

    // Deconstructor
    ~Joystick();

    // Methods
    void update();

    char *getDevice();
    void getDevice(char *device);
    unsigned char getNumAxes();
    unsigned char getNumButtons();
    int getVersion();
    char *getName();
    void getName(char *name);
    uint8_t *getAxmap();
    void getAxmap(uint8_t *axmap);
    uint16_t *getBtnmap();
    void getBtnmap(uint16_t *btnmap);
    int *getAxis();
    void getAxis(int *axis);
    int getAxis(int index);
    char *getButton();
    void getButton(char *button);
    char getButton(int index);

    // Names
    static char const *const axis_name[ABS_MAX + 1];
    static char const *const button_name[KEY_MAX - BTN_MISC + 1];

protected:

    // Members
    char* device;
    pthread_t thread;
    int fd;
    unsigned char numAxes;
    unsigned char numButtons;
    int version;
    char *name;
    uint8_t *axmap;
    uint16_t *btnmap;
    int *axis;
    char *button;

};

